from .one_hot import *
from .calculate_metric import *
import os
from datetime import datetime

# 创建日志文件
log_dir = "logs"
os.makedirs(log_dir, exist_ok=True)
log_file_path = os.path.join(log_dir, f"current_{datetime.now().strftime('%Y%m%d_%H%M%S')}.log")

def dual_print(*args, **kwargs):
    """
    同时输出到控制台和文件的print函数
    """
    # 构建输出字符串
    output = " ".join(str(arg) for arg in args)
    
    # 输出到控制台
    print(*args, **kwargs)
    
    # 输出到文件
    try:
        with open(log_file_path, 'a', encoding='utf-8') as f:
            timestamp = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
            f.write(f"[{timestamp}] {output}\n")
            f.flush()  # 确保立即写入文件
    except Exception as e:
        # 如果写入文件失败，只在控制台显示错误
        print(f"Warning: Failed to write to log file: {e}")
